/**
 * 设备投放列表排列格式，传入排入的设备类型，返回相应的排列格式
 * @param {Array} dataList 设备投放列表数据
 * @param {Number} machineType 设备类型
 * */
export const handProjectList = (dataList, machineType) => {
  dataList.sort((a, b) => {
    return parseInt(a.roadNumber) - parseInt(b.roadNumber)
  })

  const newGroupRoadNumbers = {
    2: [
      '11',
      '12',
      '13',
      '14',

      '21',
      '22',
      '23',
      '24',

      '31',
      '32',
      '33',
      '34',

      '41',
      '42',
      '43',
      '44',

      '51',
      '52',
      '53',
      '54',

      '61',
      '62',
      '63',
      '64',

      '71',
      '72',
      '73',
      '74',

      '81',
      '82',
      '83',
      '84',

      '91',
      '92',
      '93',
      '94',

      '101',
      '102',
      '103',
      '104',

      '111',
      '112',
      '113',
      '114',

      '121',
      '122',
      '123',
      '124',

      '131',
      '132',
      '133',
      '134',

      '141',
      '142',
      '143',
      '144',

      '151',
      '152',
      '153',
      '154',
    ],
    3: [
      '11',
      '12',
      '13',

      '21',
      '22',
      '23',

      '31',
      '32',
      '33',

      '41',
      '42',
      '43',

      '51',
      '52',
      '53',

      '61',
      '62',
      '63',

      '71',
      '72',
      '73',

      '81',
      '82',
      '83',
    ],
    4: [
      '11',
      '12',
      '13',
      '14',

      '21',
      '22',
      '23',
      '24',

      '31',
      '32',
      '33',
      '34',

      '41',
      '42',
      '43',
      '44',

      '51',
      '52',
      '53',
      '54',

      '61',
      '62',
      '63',
      '64',

      '71',
      '72',
      '73',
      '74',

      '81',
      '82',
      '83',
      '84',

      '91',
      '92',
      '93',
      '94',
    ],
    5: [
      '11',
      '12',
      '13',

      '21',
      '22',
      '23',

      '31',
      '32',
      '33',

      '41',
      '42',
      '43',

      '51',
      '52',
      '53',

      '61',
      '62',
      '63',

      '71',
      '72',
      '73',

      '81',
      '82',
      '83',

      '91',
      '92',
      '93',

      '101',
      '102',
      '103',

      '111',
      '112',
      '113',

      '121',
      '122',
      '123',
    ],
  }
  const groupedData = newGroupRoadNumbers[machineType].map((roadNumber) => {
    return dataList.filter((item) => item.roadNumber === roadNumber)
  })
  const splitArrays = []
  if (machineType === 3 || machineType === 5) {
    for (let i = 0; i < groupedData.length; i += 3) {
      const list = groupedData.slice(i, i + 3).map((item) => {
        return item.length ? item : undefined
      })

      splitArrays.push(list.flat())
    }
  } else {
    for (let i = 0; i < groupedData.length; i += 4) {
      const list = groupedData.slice(i, i + 4).map((item) => {
        return item.length ? item : undefined
      })

      splitArrays.push(list.flat())
    }
  }

  return splitArrays
}
